﻿using AutoMapper;
using KDS.Mes.Mes.Parts.Dtos;

namespace KDS.Mes.Mes.Parts.Mappers
{
    /// <summary>
    /// PartDto映射配置
    /// </summary>
    public class PartDtoMapper
    {
        private static volatile bool _mappedBefore;
        private static readonly object SyncObj = new object();

        /// <summary>
        /// 初始化映射
        /// </summary>
        public static void CreateMappings(IMapperConfigurationExpression configuration)
        {
            lock (SyncObj)
            {
                if (_mappedBefore)
                {
                    return;
                }

                CreateMappingsInternal(configuration);

                _mappedBefore = true;
            }
        }

        /// <summary>
        ///    Configuration.Modules.AbpAutoMapper().Configurators.Add(PartDtoMapper.CreateMappings);
        ///注入位置    < see cref = "MesApplicationModule" />
        /// <param name="configuration"></param>
        /// </summary>
        private static void CreateMappingsInternal(IMapperConfigurationExpression configuration)
        {
            var partDtoMapper = configuration.CreateMap<Part, PartListDto>();
            partDtoMapper.ForMember(dto => dto.AlcCode, map => map.MapFrom(m => m.AlcCode.ALCCode));
            partDtoMapper.ForMember(dto => dto.SeatPositionName, map => map.MapFrom(m => m.SeatPosition.SeatPositionName));
            //var partDtoMapper = configuration.CreateMap<Part, PartListDto>();

            //默认ABP功能已经实现了，如果你要单独对DTO进行拓展，可以在此处放开注释文件。

            // Configuration.Modules.AbpAutoMapper().Configurators.Add(PartDtoMapper.CreateMappings);

            //    Mapper.CreateMap<Part,PartEditDto>();
            //     Mapper.CreateMap<Part, PartListDto>();

            //       Mapper.CreateMap<PartEditDto, Part>();
            //        Mapper.CreateMap<PartListDto,Part>();
        }
    }
}